package org.uniexception.exception;

import org.uniexception.util.UniExceptionUtil;
import org.uniexception.EnvConfig;

public class UserDefinedException extends Throwable implements UserDefinedCommonExceptionInterface {
    private String userMsg;

    private Object[] params;

    private String statckTraceStr;

    private EnvConfig envConfig;

    public UserDefinedException(Throwable rootCause,String useMsg,Object... params)
    {
     super(rootCause);
     this.userMsg = useMsg;
     this.params = params;
     initStatckTraceStr();
    }

    public UserDefinedException(Throwable rootCause,String useMsg)
    {
        super(rootCause);
        this.userMsg = useMsg;
        initStatckTraceStr();
    }


    public UserDefinedException(Throwable rootCause)
    {
        super(rootCause);
        initStatckTraceStr();

    }
    public String getUserMsg() {
        return userMsg;
    }

    public void setUserMsg(String userMsg) {
        this.userMsg = userMsg;
    }

    public Object[] getParams() {
        return params;
    }

    public void setParams(Object[] params) {
        this.params = params;
    }

    public String getStatckTraceStr() {
        return statckTraceStr;
    }

    public void setStatckTraceStr(String statckTraceStr) {
        this.statckTraceStr = statckTraceStr;
    }

    public void setEnvConfig(EnvConfig envConfig) {
        this.envConfig = envConfig;
    }

    public EnvConfig getEnvConfig() {
             return envConfig;
    }

    private void initStatckTraceStr()
    {
        if(this.params != null && this.params.length>0)
        {  StringBuffer buf = new StringBuffer();
            for(int idx = 0;idx<this.params.length;++idx)
            {
                buf.append("params").append(idx).append(this.params[idx]);
            }
            buf.append("\n");
            buf.append(UniExceptionUtil.getStacktraceStr(this));
            this.statckTraceStr =  buf.toString();
        }

    }
}
